angular.module('imsApp').controller('resetPasswordCtrl', ['$scope','$uibModalInstance','user', 'AuthManager',function ($scope,$uibModalInstance,user,AuthManager) {
    $scope.user=user;


    var resetPassword=function () {
        if(!$scope.user.oldPsw||!$scope.user.newPsw||!$scope.user.newPswSure){
            $scope.message="不允许为空";
            return false;
        }
        if($scope.user.newPsw!=$scope.user.newPswSure){
            $scope.message="两次密码输入不一致";
            return false;

        }
        AuthManager.resetPassword({oldPsw:$scope.user.oldPsw,newPsw:$scope.user.newPsw}).then(function (result) {
            if(result.data.c=="s"){
                $uibModalInstance.dismiss();
                $scope.userInfo.token=result.data.i;
                localStorage.setItem("userInfo",JSON.stringify($scope.userInfo));

            }else{
                $scope.message=result.data.i;
            }

        })
    }
    $scope.ok = function () {
        resetPassword();
    };

    $scope.cancel = function () {
        $uibModalInstance.dismiss('cancel');
    };


}])

